package ar.com.pragmatia.lanacion.app;

import android.app.Activity;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.provider.Settings.Secure;
import android.util.Log;
import ar.com.pragmatia.lanacion.data.DataHelper;
import ar.com.pragmatia.lanacion.data.User;

public class App {

	static DataHelper dataHelper = null;
	static String deviceId = "";
	static ConnectivityManager cm = null;
	static User user;

	// static String deviceScreen = "";

	public static void initializate(Activity activity) {
		App.setDataHelper(new DataHelper(activity.getApplicationContext()));
		cm = (ConnectivityManager) activity
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		App.setDeviceId(Secure.getString(activity.getApplicationContext()
				.getContentResolver(), Secure.ANDROID_ID));

		User user = new User();
		user.initialize();
		App.setUser(user);
	}

	public static boolean isNetworkAvailable() {

		// if no network is available networkInfo will be null, otherwise check
		// if we are connected
		ConnectivityManager cm = App.getConnectivityManager();
		NetworkInfo ni = cm.getActiveNetworkInfo();

		if (ni != null && ni.isConnected()) {
			return true;
		}

		return false;
	}

	public static DataHelper getDataHelper() {
		return App.dataHelper;
	}

	public static void setDataHelper(DataHelper dataHelper) {
		App.dataHelper = dataHelper;
	}

	public static SQLiteDatabase getDb() {
		return App.dataHelper.getDb();
	}

	public static String getDeviceId() {
		return deviceId;
	}

	public static void setDeviceId(String deviceId) {
		App.deviceId = deviceId;
	}

	public static ConnectivityManager getConnectivityManager() {
		return cm;
	}

	public static void setCm(ConnectivityManager cm) {
		App.cm = cm;
	}

	public static User getUser() {
		return user;
	}

	public static void setUser(User user) {
		App.user = user;
	}

	public static void log(String clazz, String method, String msg) {
		Log.d("LaNacion", "Class: " + clazz + ", Method: " + method + ", "
				+ msg);
	}

}
